Skip to content

Conversation

@joaquim-verges
Copy link
Member

@joaquim-verges joaquim-verges commented Feb 10, 2025

Fixes #6203


PR-Codex overview

This PR focuses on enhancing session key management in the thirdweb library by adding a new function, shouldUpdateSessionKey, which determines if a session key's permissions should be updated based on various conditions.

Detailed summary

  • Added shouldUpdateSessionKey function in packages/thirdweb/src/extensions/erc4337/account/addSessionKey.ts.
  • Updated connectSmartAccount function to utilize shouldUpdateSessionKey for session key checks.
  • Modified imports to include shouldUpdateSessionKey where necessary.
  • Added tests for shouldUpdateSessionKey in packages/thirdweb/src/extensions/erc4337/account/permissions.test.ts.

✨ Ask PR-Codex anything about this PR by commenting with /codex {your question}

@vercel
Copy link

vercel bot commented Feb 10, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
docs-v2 ✅ Ready (Inspect) Visit Preview 💬 Add feedback Feb 10, 2025 7:45pm
login ✅ Ready (Inspect) Visit Preview 💬 Add feedback Feb 10, 2025 7:45pm
thirdweb_playground ✅ Ready (Inspect) Visit Preview 💬 Add feedback Feb 10, 2025 7:45pm
thirdweb-www ✅ Ready (Inspect) Visit Preview 💬 Add feedback Feb 10, 2025 7:45pm
wallet-ui ✅ Ready (Inspect) Visit Preview 💬 Add feedback Feb 10, 2025 7:45pm

@changeset-bot
Copy link

changeset-bot bot commented Feb 10, 2025

🦋 Changeset detected

Latest commit: f42af42

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 3 packages
Name Type
thirdweb Patch
@thirdweb-dev/wagmi-adapter Patch
thirdweb-login Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@github-actions github-actions bot added packages SDK Involves changes to the thirdweb SDK labels Feb 10, 2025
@joaquim-verges joaquim-verges marked this pull request as ready for review February 10, 2025 08:31
@joaquim-verges joaquim-verges requested review from a team as code owners February 10, 2025 08:31
Copy link
Member Author


How to use the Graphite Merge Queue

Add either label to this PR to merge it via the merge queue:

  • merge-queue - adds this PR to the back of the merge queue
  • hotfix - for urgent hot fixes, skip the queue and merge this PR next

You must have a Graphite account in order to use the merge queue. Sign up using this link.

An organization admin has enabled the Graphite Merge Queue in this repository.

Please do not merge from GitHub as this will restart CI on PRs being processed by the merge queue.

This stack of pull requests is managed by Graphite. Learn more about stacking.

@github-actions
Copy link
Contributor

github-actions bot commented Feb 10, 2025

size-limit report 📦

Path Size Loading time (3g) Running time (snapdragon) Total time
thirdweb (esm) 46.28 KB (0%) 926 ms (0%) 690 ms (+151.63% 🔺) 1.7 s
thirdweb (cjs) 122.06 KB (0%) 2.5 s (0%) 881 ms (-12.91% 🔽) 3.4 s
thirdweb (minimal + tree-shaking) 5.6 KB (0%) 112 ms (0%) 88 ms (+214.72% 🔺) 200 ms
thirdweb/chains (tree-shaking) 506 B (0%) 10 ms (0%) 32 ms (+225.35% 🔺) 42 ms
thirdweb/react (minimal + tree-shaking) 19.3 KB (+0.03% 🔺) 387 ms (+0.03% 🔺) 197 ms (+37.45% 🔺) 583 ms

@codecov
Copy link

codecov bot commented Feb 10, 2025

Codecov Report

Attention: Patch coverage is 96.92308% with 2 lines in your changes missing coverage. Please review.

Project coverage is 56.78%. Comparing base (c86e13b) to head (f42af42).
Report is 8 commits behind head on main.

Files with missing lines Patch % Lines
...eb/src/extensions/erc4337/account/addSessionKey.ts 96.49% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #6217      +/-   ##
==========================================
+ Coverage   56.72%   56.78%   +0.05%     
==========================================
  Files        1161     1161              
  Lines       64289    64342      +53     
  Branches     5196     5219      +23     
==========================================
+ Hits        36468    36535      +67     
+ Misses      27095    27079      -16     
- Partials      726      728       +2     
Flag Coverage Δ *Carryforward flag
legacy_packages 65.68% <ø> (ø) Carriedforward from c86e13b
packages 54.97% <96.92%> (+0.07%) ⬆️

*This pull request uses carry forward flags. Click here to find out more.

Files with missing lines Coverage Δ
packages/thirdweb/src/wallets/smart/index.ts 61.03% <100.00%> (-0.34%) ⬇️
...eb/src/extensions/erc4337/account/addSessionKey.ts 95.06% <96.49%> (+3.39%) ⬆️

... and 5 files with indirect coverage changes

Comment on lines +128 to +132
if (
!areSessionKeyContractTargetsEqual(
currentPermissions.approvedTargets,
newPermissions.approvedTargets,
)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of checking for equality, it could check for subests to minimize the need for creating sessions (i.e., currentPermissions.approvedTargets includes at least all of newPermissions.approvedTargets)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you! Looks great

Comment on lines 138 to 140
if (
currentPermissions.nativeTokenLimitPerTransaction !==
toWei(newPermissions.nativeTokenLimitPerTransaction?.toString() ?? "0")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Again instead of equality, this could be currentPermissions.nativeTokenLimitPerTransaction >= newPermissions.nativeTokenLimitPerTransaction

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

* @param newPermissions - The new permissions to set for the session key.
* @returns A boolean indicating if the session key should be updated.
*/
export async function shouldUpdateSessionKey(args: {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We also check on startDate and isAdmin values in our current version of this logic, but not sure if that's important here.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

start date is a bit weird, decided to leave it alone for this. And yeah admin should be separate i think?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

packages SDK Involves changes to the thirdweb SDK

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Smart wallet session key auto-creation doesn't take into account permissions when skipping

3 participants